package es.tessier.asteroides;

import android.content.Context;
import android.os.Bundle;
import android.preference.PreferenceActivity;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;

public class Preferences extends PreferenceActivity {
	
	private static final String OPT_MUSIC = "music";
	private static final boolean OPT_MUSIC_DEF = true;
	
	private static final String OPT_GRAPHICS = "graphics";
	private static final int OPT_GRAPHICS_DEF =0 ;
	
	private static final String OPT_FRAGMENTS = "fragments";
	private static final int OPT_FRAGMENTS_DEF = 3;


	@Override
	protected void onCreate(final Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		getFragmentManager().beginTransaction()
				.replace(android.R.id.content, new MyPreferenceFragment())
				.commit();
	}

	public static class MyPreferenceFragment extends PreferenceFragment {
		@Override
		public void onCreate(final Bundle savedInstanceState) {
			super.onCreate(savedInstanceState);
			addPreferencesFromResource(R.xml.preferences);
		}
	}

	public static boolean getMusic(Context context) {
		return PreferenceManager.getDefaultSharedPreferences(context)
				.getBoolean(OPT_MUSIC, OPT_MUSIC_DEF);
	}

	public static int  getGraphics(Context context) {
		return PreferenceManager.getDefaultSharedPreferences(context)
				.getInt(OPT_GRAPHICS, OPT_GRAPHICS_DEF);
	}

	
	public static int getHints(Context context) {
		return PreferenceManager.getDefaultSharedPreferences(context)
				.getInt(OPT_FRAGMENTS, OPT_FRAGMENTS_DEF);
	}
}